package com.lwl.office.webeditor.tools;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;

import java.math.BigInteger;

public class ConvertUtil {
    /**
     * html中的行高转word中的行高
     *  word中单行行高240 ，html中单行行高1.0em
     * @param lineEm
     * @return
     */
    public static BigInteger html2WordLineHeight(String lineEm){
        String numStr = lineEm.replace("em", "");
        return BigInteger.valueOf((long) (240 * Double.parseDouble(numStr)));
    }


    public static CTString ctsOf(String str){
        CTString ctString = CTString.Factory.newInstance();
        ctString.setVal(str);
        return ctString;
    }
    public static CTDecimalNumber ctnOf(Integer n){
        CTDecimalNumber ctn = CTDecimalNumber.Factory.newInstance();
        ctn.setVal(BigInteger.valueOf(n));
        return ctn;
    }
    /**
     *  px
     * @param sz n px
     * @return n * 1.5
     */
    public static int toWordFontSize(String sz){
        double px = Double.parseDouble(sz.replace("px", ""));
        return (int) (px*1.5);
    }

    /**
     *
     * @param color
     * @return
     */
    public static String toHexColor(String color) {
        if(color.startsWith("#")){
            return color.replace("#","");
        }
        return "000000";
    }

    public static Integer toWordImageLen(String len) {
        return Integer.parseInt(len);
    }
}
